package com.qqonline.mpf;

import java.io.File;

import com.qqonline.conmon.AsyncImageTask;
import com.qqonline.conmon.GetUrlPicUri;

import android.content.Context;
import android.database.DataSetObserver;
import android.net.Uri;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

public class PicAdapter implements ListAdapter {
	public PicActivity activity;
	public LayoutInflater mInflater;
	private Display display;
	public PicAdapter(PicActivity mainActivity,Display display) {
		this.activity = mainActivity;
		this.display=display;
		this.mInflater  = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public void registerDataSetObserver(DataSetObserver observer) {
		// TODO Auto-generated method stub

	}

	@Override
	public void unregisterDataSetObserver(DataSetObserver observer) {
		// TODO Auto-generated method stub

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return activity.picList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return activity.picGridView.getItemAtPosition(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;
        if (convertView != null) {
                view = convertView;
        } else {
                view = mInflater.inflate(R.layout.picgriditem, null);
        }
        ImageView img= (ImageView) view.findViewById(R.id.phoneImage);
        String phoneImage = activity.picList.get(position).getPicUrl();
        AsyncImageTask imageTask = new AsyncImageTask(img,activity,display);
        imageTask.execute(phoneImage);
		return view;
	}

	@Override
	public int getItemViewType(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		return 1;
	}

	@Override
	public boolean isEmpty() {
		if(activity.picList.size()<1){
			return false;
			}
			return true;
	}

	@Override
	public boolean areAllItemsEnabled() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isEnabled(int position) {
		// TODO Auto-generated method stub
		return false;
	}

}
